package com;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public abstract class Database{

	protected Connection connect;
	protected PreparedStatement preparedStatement;
	protected ResultSet resultSet;
		
	protected void connectToDatabase() throws Exception{
		// Load the MySQL driver and connect to the database
		Class.forName("com.mysql.jdbc.Driver").newInstance();
		connect = DriverManager.getConnection("jdbc:mysql://localhost:3306/citiquantsDB", "root", "root");	
	}
	
	// Make sure all the connections are closed
	protected void close() {
		close(resultSet);
		close(preparedStatement);
		close(connect);
	}
	
	private void close(AutoCloseable c){
		try{
			if (c != null){
				c.close();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}